package String;

public class 反转字符串2 {
    public String reverseStr(String s, int k) {
        char[] c = s.toCharArray();
        for (int l = 0; l < c.length; l += 2 * k) {
            int r = Math.min(c.length, l + k) - 1;
            reverse(c, l, r);
        }
        return new String(c);
    }

    private void reverse(char[] s, int l, int r) {
        while (l < r) {
            char t = s[l];
            s[l] = s[r];
            s[r] = t;
            l++;
            r--;
        }
    }
}
